// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/face/api/FacePersonApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/face/model/FaceSnapRecordReq'
import DelClass from '@api/face/model/FacePersonDeleteReq'
import SubmitOneClass from '@api/face/model/SyncOnePersonManyDeviceReq'
import SubmitAllClass from '@api/face/model/SyncStatusPersonReq'
import BaseClass from '@api/face/model/FacePersonDto'

const AddClass = ListClass
const EditClass = ListClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询人员信息列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'facePersonQuery', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增人员信息') {
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'facePersonSave', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = '修改人员信息') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'facePersonUpdate', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除人员信息') {
    const DTO = CORE.grpcDTO(DelClass, { ids: id })
    await CORE.grpc(TIP, CLIENT, 'facePersonDelete', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submitOne(one, TIP = '重新建模') {
    const DTO = CORE.grpcDTO(SubmitOneClass, one)
    await CORE.grpc(TIP, CLIENT, 'syncStatusOneDevice', DTO)
    return `${TIP}：已提交`
  },

  async submitMulti(one, TIP = '重新建模') {
    const DTO = CORE.grpcDTO(SubmitAllClass, one)
    await CORE.grpc(TIP, CLIENT, 'syncStatusPerson', DTO)
    return `${TIP}：已提交`
  },

  async submitAll(one, TIP = '全部重新建模') {
    const DTO = CORE.grpcDTO(SubmitAllClass, { ...one, facePersonId: one.facePersonIdList })
    await CORE.grpc(TIP, CLIENT, 'syncStatusPerson', DTO)
    return `${TIP}：已提交`
  },
}
